(function(){
	var more = function(){
		this.initLeft = 5 ;
		this.width = 54 ;
		this.sonWidth = 40; 
		
		this.length = 0 ;
		
		this.isExecuting = false ;
		this.timec = null ;
		this.isOpen = false;
		
		this.more_obj = null ;
	} ;
	

	more.prototype.refresh = function(id){
		var _me = this ;
		_me.more_obj = id && $("#" + id ) || $('div[data-role="more"]');
	 	_me.init();
		
		$('a[data-role="control"]',_me.more_obj).unbind("click").bind("click",function(){
			//length = $('a[data-role!="control"]','div[data-role="more"]').length ;
			_me.length = $(this).siblings("a").length ;
			if(_me.isExecuting)
				return ;
			_me.isExecuting = true;
			var sibs = $(this).nextAll();
			if(!_me.isOpen){
				$(sibs).each(function(index){
					setTimeout(_me.dispose(this, index), 100 * (index + 1));
				});
				_me.isOpen = true;
			}else{
				var len = sibs.length ;
				$(sibs).each(function(index){
					setTimeout(_me.dispose(this, index, true), 100 * (len - index + 1)) ;
				});
				_me.isOpen = false;
			}
			
			_me.timec = setTimeout((function(_me){
				return enableClick(_me);
			})(_me), 200 );
		});
		
	}
	
	more.prototype.init = function(){
		this.length = $('a[data-role!="control"]',this.more_obj).length ;
		if(this.length == 0){
			$(this.more_obj).remove();
			return ;
		}else if(this.length == 1){ 
			$('a[data-role="control"]',this.more_obj).hide();  
			$('a[data-role!="control"]',this.more_obj).show();
			$('a[data-role!="control"]',this.more_obj).css({
				width : 54 ,
				height : 54 ,
				left : 0 ,
				top : 0
			});
		}else{ 
			$('a[data-role="control"]',this.more_obj).show();
			$('a[data-role!="control"]',this.more_obj).hide();
			$('a[data-role!="control"]',this.more_obj).css({
				width : 40 ,
				height : 40 ,
				left : 5 ,
				top : 8
			});
		}
		
		$(this.more_obj).css({
			"width" : this.width
		}).find('a[data-role!="control"]').css({
			left : this.initLeft 
		});
		$(this.more_obj).removeClass("open");
		this.isOpen = false;
	}
	
	more.prototype.dispose = function(obj, index, flag){
		var _me = this ;
		if (flag) {
			return function(){
				var left = $(obj).attr("data-init-left");
				$(obj).animate({
					left: _me.initLeft
				}, 120,function(){
					$(obj).hide();
					$(obj).parent().removeClass("open").css({
						"width" : _me.width
					});
				});
			};
		} else {
			return function(){
				$(obj).show();
				$(obj).animate({
					left : _me.width + index * _me.sonWidth + (index+1) * 10
				}, 120, function(){
					$(obj).parent().addClass("open").css({
						width : _me.width + (_me.sonWidth + 10) * _me.length + 10
					});
				});
			};
		}
	}
	

	var enableClick = function(_me){
		_me.isExecuting = false ;
		if(_me.timec != null)
			clearTimeout(_me.timec);
		_me.timec = null ;
	}
	
	function _obj(){
		return new more() ;
	}
	
	window.HQCH_MORE = _obj(); 
})();